package com.jbinfo.common.utils;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class DataCommUtil {
	// List 去重
	public static void removeDup(List<String> strList) {
		Set<String> hSet = new HashSet<String>(strList);
		strList.clear();
		strList.addAll(hSet);
	}
	
	// 获取两个日期之间所有日期
	public static List<String> printDay(Calendar startDay, Calendar endDay) {
		
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		
		List<String> dayList = new ArrayList<String>();
		
		// 给出的日期开始日期大于结束日期，则不执行打印  
		  if (startDay.compareTo(endDay) > 0) {
			  return null;  
		  }
		// 现在打印中的日期  
		  Calendar currentPrintDay = startDay;
		  if (currentPrintDay.compareTo(endDay) == 0) { 
			  // 如果开始日期等于结束日期，则打印开始日期即可
			  String strCurDate = sdf.format(currentPrintDay.getTime());
			  dayList.add(strCurDate);
		  } else {
			  while (true) {
				  	// 日期加一  
				   currentPrintDay.add(Calendar.DATE, 1);
				   // 日期加一后判断是否达到终止日期，达到则终止打印  
				   if (currentPrintDay.compareTo(endDay) > 0) {  
					   break;  
				   }
				   
				   String strCurDate = sdf.format(currentPrintDay.getTime());
				   dayList.add(strCurDate);
			  }
		  }
		  
		  
		  return dayList;
	}
}
